#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 20.py
# @time: 2025/1/22
# @software: PyCharm

class Solution:
    def isValid(self, s: str) -> bool:
        result = False
        kv = {
            ")":"(",
            "]":"[",
            "}":"{",
        }
        if len(s) % 2 == 0:
            st = list()
            loop = True
            for ch in s:
                if ch == "(" or ch == "[" or ch == "{":
                    st.append(ch)
                else:
                    if len(st) > 0 and kv[ch]==st[-1]:
                        st.pop()
                    else:
                        loop = False
                        break
            if loop:
                result = len(st) == 0
        return result


if __name__ == "__main__":
    solu = Solution()
    result = solu.isValid("}(")
    print(result)
